package com.example.maruko_course_backend.aop;

import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ExceptionConfiguration {
    public static final String traceExecution = "execution(* com.example.maruko_course_backend..*.*(..))";

    @Bean
    public DefaultPointcutAdvisor exceptionPointcutAdvisor() {
        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
        advisor.setPointcut(createAspectJExpressionPointcut());
        advisor.setAdvice(new ExceptionAdvice());
        return advisor;
    }

    private AspectJExpressionPointcut createAspectJExpressionPointcut() {
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression(traceExecution);
        return pointcut;
    }
}
